import { pinia, IUserState, PERSIST as persist, STORE } from '@/store'

const useUserStore = defineStore<string, IUserState>(
  STORE.USER,
  () => {
    const pcRoutes = ref<RouteRecordRaw[]>([])
    const redirectPath = ref('/tpls/edit-tpl')

    const addRoutesOfRoles = (routes: RouteRecordRaw[]) => {
      pcRoutes.value = routes
    }
    const changeRedirectPath = (path: string) => {
      redirectPath.value = path
    }

    return {
      pcRoutes,
      redirectPath,
      addRoutesOfRoles,
      changeRedirectPath,
    }
  },
  {
    persist,
  }
)

export const useUserStoreOutside = () => {
  return useUserStore(pinia)
}

export default useUserStore
